//create gt-itm config file

#include<cstdio>
#include<cstdlib>
#include<ctime>

int uniform( int min, int max ){
	return (rand()%(max-min+1))+min;
}

int main( int argc, char** argv ){
	
	srand( time(0) );
	
	system( "rm -f VNs/*" );

	int number_of_VNs;
	int min_size;
	int max_size;
	int min_processing;
	int max_processing;
	int min_bandwidth;
	int max_bandwidth;
	int min_profit;
	int max_profit;
	
	sscanf( argv[1], "%d", &number_of_VNs );
	sscanf( argv[2], "%d", &min_size );
	sscanf( argv[3], "%d", &max_size );
	sscanf( argv[4], "%d", &min_processing );
	sscanf( argv[5], "%d", &max_processing );
	sscanf( argv[6], "%d", &min_bandwidth );
	sscanf( argv[7], "%d", &max_bandwidth );
	sscanf( argv[8], "%d", &min_profit );
	sscanf( argv[9], "%d", &max_profit );

	
	for( int i = 0; i < number_of_VNs; ++i ) {
		FILE* out;
		char out_file[100];
		
		sprintf( out_file, "VNs/vn_conf%d", i );
		out = fopen( out_file, "w" );
		if( !out ){
			printf( "Error in file generate_VNs.cpp, function main: Could not open file VNs/vn_conf%d\n", i );
			exit(-1);
		}
		
		int size = uniform( min_size, max_size );
		int profit = uniform( min_profit, max_profit );
		
		fprintf( out, "# <method keyword> <number of graphs> [<initial seed>]\n" );
		fprintf( out, "# <n> <scale> <edgemethod> <alpha> [<beta>] [<gamma>]\n" );
		fprintf( out, "geo 1 %d\n", rand() );
		fprintf( out, "%d 1000 3 0.5\n", size );
		
		fclose( out );
		
		char cmd1[100];
		char cmd2[100];
		char cmd3[100];
		char cmd4[50];
		char cmd5[50];
		char cmd6[50];
		sprintf( cmd1, "./../softwares/gt-itm/bin/itm VNs/vn_conf%d", i );
		sprintf( cmd2, "./../softwares/gt-itm/bin/sgb2alt VNs/vn_conf%d-0.gb VNs/vn%d", i, i );
		sprintf( cmd3, "./utils/convert_gt-itm_format VNs/vn%d VNs/vn%d.net %d %d %d %d %d %d", i, i, min_processing, max_processing, min_bandwidth, max_bandwidth, profit, rand() );
		sprintf( cmd4, "rm VNs/vn_conf%d", i );
		sprintf( cmd5, "rm VNs/vn_conf%d-0.gb", i );
		sprintf( cmd6, "rm VNs/vn%d", i );
		
		system( cmd1 );
		system( cmd2 );
		system( cmd3 );
		system( cmd4 );
		system( cmd5 );
		system( cmd6 );
	}

}